<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,IE=9,chrome=1"><meta name="generator" content="MATLAB 2023a"><title>Untitled</title><style type="text/css">.rtcContent { padding: 30px; } .S0 { margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;  }
.CodeBlock { background-color: #F5F5F5; margin: 10px 0 10px 0; }
.S1 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S2 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S3 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S4 { color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px;  }</style></head><body><div class = rtcContent><div  class = 'S0'><span>输入图像</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S1'><span style="white-space: pre"><span >original = imread(</span><span style="color: rgb(167, 9, 245);">"R-C.jpg"</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >tiledlayout(1, 1);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(original);</span></span></div></div><div class="inlineWrapper outputs"><div  class = 'S3'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"Origin Image"</span><span >);</span></span></div><div  class = 'S4'><div class="inlineElement eoOutputWrapper embeddedOutputsFigure" uid="EBDEBD57" prevent-scroll="true" data-testid="output_0" style="width: 1043px;"><div class="figureElement eoOutputContent"><img class="figureImage figureContainingNode" src="" style="width: 426px; padding-bottom: 0px;"></div><div class="outputLayer selectedOutputDecorationLayer doNotExport"></div><div class="outputLayer activeOutputDecorationLayer doNotExport"></div><div class="outputLayer scrollableOutputDecorationLayer doNotExport"></div></div></div></div></div><div  class = 'S0'><span>将图像转化为灰度图</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S1'><span style="white-space: pre"><span >grayu8 = im2gray(original);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">% grayi16 = im2int16(grayu8);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >tiledlayout(1, 1);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(grayu8);</span></span></div></div><div class="inlineWrapper outputs"><div  class = 'S3'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"Grayscale Image (in `uint8`)"</span><span >);</span></span></div><div  class = 'S4'><div class="inlineElement eoOutputWrapper embeddedOutputsFigure" uid="497C4EC5" prevent-scroll="true" data-testid="output_1" style="width: 1043px;"><div class="figureElement eoOutputContent"><img class="figureImage figureContainingNode" src="" style="width: 426px; padding-bottom: 0px;"></div><div class="outputLayer selectedOutputDecorationLayer doNotExport"></div><div class="outputLayer activeOutputDecorationLayer doNotExport"></div><div class="outputLayer scrollableOutputDecorationLayer doNotExport"></div></div></div></div></div><div  class = 'S0'><span>阈值处理</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S1'><span style="white-space: pre"><span >otsued = imbinarize(grayu8);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >adapted = imbinarize(grayu8, </span><span style="color: rgb(167, 9, 245);">"adaptive"</span><span >, </span><span style="color: rgb(167, 9, 245);">"ForegroundPolarity"</span><span >, </span><span style="color: rgb(167, 9, 245);">"dark"</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >thresh64 = imbinarize(grayu8, 64 / 255);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >thresh96 = imbinarize(grayu8, 96 / 255);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >threshmid = imbinarize(grayu8, 0.5);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >thresh160 = imbinarize(grayu8, 160 / 255);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >tiledlayout(2, 3);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(otsued);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"Otsu"</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(adapted);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"Adaptive"</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(thresh64);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"64/255"</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(thresh96);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"96/255"</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(threshmid);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"0.5"</span><span >)</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(thresh160);</span></span></div></div><div class="inlineWrapper outputs"><div  class = 'S3'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"160/255"</span><span >)</span></span></div><div  class = 'S4'><div class="inlineElement eoOutputWrapper embeddedOutputsFigure" uid="AB83CEED" prevent-scroll="true" data-testid="output_2" style="width: 1043px;"><div class="figureElement eoOutputContent"><img class="figureImage figureContainingNode" src="" style="width: 426px; padding-bottom: 0px;"></div><div class="outputLayer selectedOutputDecorationLayer doNotExport"></div><div class="outputLayer activeOutputDecorationLayer doNotExport"></div><div class="outputLayer scrollableOutputDecorationLayer doNotExport"></div></div></div></div></div><div  class = 'S0'><span>边缘检测 (使用 "96/255")</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S1'><span style="white-space: pre"><span >[sobeled, thr_sobel] = edge(thresh96, </span><span style="color: rgb(167, 9, 245);">"sobel"</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >[prewitted, thr_prewitt] = edge(thresh96, </span><span style="color: rgb(167, 9, 245);">"prewitt"</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >[robertsed, thr_roberts] = edge(thresh96, </span><span style="color: rgb(167, 9, 245);">"roberts"</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >[cannyed, thr_canny] = edge(thresh96, </span><span style="color: rgb(167, 9, 245);">"canny"</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >tiledlayout(2, 2);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(sobeled);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"Sobel"</span><span >)</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(prewitted);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"Prewitt"</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(robertsed);</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"Roberts"</span><span >)</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nexttile;</span></span></div></div><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >imshow(cannyed);</span></span></div></div><div class="inlineWrapper outputs"><div  class = 'S3'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">"Canny"</span><span >);</span></span></div><div  class = 'S4'><div class="inlineElement eoOutputWrapper embeddedOutputsFigure" uid="FA280E25" prevent-scroll="true" data-testid="output_3" style="width: 1043px;"><div class="figureElement eoOutputContent"><img class="figureImage figureContainingNode" src="" style="width: 426px; padding-bottom: 0px;"></div><div class="outputLayer selectedOutputDecorationLayer doNotExport"></div><div class="outputLayer activeOutputDecorationLayer doNotExport"></div><div class="outputLayer scrollableOutputDecorationLayer doNotExport"></div></div></div></div></div>
<br>
<!-- 
##### SOURCE BEGIN #####
%% 
% 输入图像

original = imread("R-C.jpg");

tiledlayout(1, 1);
nexttile;
imshow(original);
title("Origin Image");
%% 
% 将图像转化为灰度图

grayu8 = im2gray(original);
% grayi16 = im2int16(grayu8);

tiledlayout(1, 1);
nexttile;
imshow(grayu8);
title("Grayscale Image (in `uint8`)");
%% 
% 阈值处理

otsued = imbinarize(grayu8);
adapted = imbinarize(grayu8, "adaptive", "ForegroundPolarity", "dark");
thresh64 = imbinarize(grayu8, 64 / 255);
thresh96 = imbinarize(grayu8, 96 / 255);
threshmid = imbinarize(grayu8, 0.5);
thresh160 = imbinarize(grayu8, 160 / 255);


tiledlayout(2, 3);

nexttile;
imshow(otsued);
title("Otsu");

nexttile;
imshow(adapted);
title("Adaptive");

nexttile;
imshow(thresh64);
title("64/255");

nexttile;
imshow(thresh96);
title("96/255");

nexttile;
imshow(threshmid);
title("0.5")

nexttile;
imshow(thresh160);
title("160/255")
%% 
% 边缘检测 (使用 "96/255")

[sobeled, thr_sobel] = edge(thresh96, "sobel");
[prewitted, thr_prewitt] = edge(thresh96, "prewitt");
[robertsed, thr_roberts] = edge(thresh96, "roberts");
[cannyed, thr_canny] = edge(thresh96, "canny");

tiledlayout(2, 2);

nexttile;
imshow(sobeled);
title("Sobel")

nexttile;
imshow(prewitted);
title("Prewitt");

nexttile;
imshow(robertsed);
title("Roberts")

nexttile;
imshow(cannyed);
title("Canny");
##### SOURCE END #####
-->
</div></body></html>